The Riordan Group

This notebook attempt to study The Riordan Group article, by Shapiro, Getu, Woan and Woodson. It is my first attempt to explain ideas and to find meaning and connections among things. We reference objects and equations explained in the article using their reference numbers in order to have a direct mapping to them.

We start with some SymPy stuff in order to setup the environment:


In [1]:
import sympy
from sympy import *
from sympy.abc import x, n, z, t, y, k

from IPython.display import display, Math, Latex

init_printing() # for nice printing, a-la' TeX

%run '../riordan-group.py'

Definitions

Let $M$ be an infinite matrix with elements $m_{ji} \in \mathbb{C}$ defined as: $$ M = (m_{ji})_{i,j \geq 0}= \left[ \begin{array}{cccccc} m_{00} & m_{01} & m_{02} & \ldots & m_{0i} & \ldots \\ m_{10} & m_{11} & m_{12} & \ldots & m_{1i} & \ldots \\ m_{20} & m_{21} & m_{22} & \ldots & m_{2i} & \ldots \\ \vdots & \vdots & \vdots & \ddots & \vdots & \\ m_{j0} & m_{j1} & m_{j2} & \ldots & m_{ji} & \ldots \\ \vdots & \vdots & \vdots & & \vdots & \ddots \\ \end{array} \right] $$

Now define $C_i(x)$ as a generating function taking coefficients from $i$-th column: $$ C_i(x) = \sum_{j=0}^{\infty}{m_{ji}x^j} $$

So the following matrix product holds: $ \left[\begin{array}{cccccc} 1 & x & x^2 & \ldots & x^j & \ldots \end{array} \right] M = \left[\begin{array}{cccccc} C_0(x) & C_1(x) & C_2(x) & \ldots & C_i(x)& \ldots \end{array} \right] $

Now assume that $C_i(x)$ can be written as $g(x)f(x)^i$, for all $i \geq 0$ where: $$ g(x) = g_0 + g_1 x + g_2 x^2 + g_3 x^3 +\ldots \\ f(x) = x + f_2 x^2 + f_3 x^3 +\ldots$$

So, there are no requirements on function $g$ while function $f$ has to obeys the following: $$f(0) = 0 \\ \left . \frac{\partial f}{\partial x} \right|_0 = 1$$

Under these assumptions we can rewrite: $ \left[\begin{array}{cccccc} 1 & x & x^2 & \ldots & x^j & \ldots \end{array} \right] M = \left[\begin{array}{cccccc} g(x) & g(x)f(x) & g(x)f(x)^2 & \ldots & g(x)f(x)^i & \ldots \end{array} \right] $

and we call a matrix $M = (g(x), f(x))$ a Riordan matrix.

Product with a vector

Now take the product on the right with a vector $\left[\begin{array}{cccccc} a_0 & a_1 & a_2 & \ldots & a_i & \ldots \end{array} \right]^T$: $$ \begin{split} \left[\begin{array}{cccccc} 1 & x & x^2 & \ldots & x^j & \ldots \end{array} \right] M \left[\begin{array}{c} a_0 \\ a_1 \\ a_2 \\ \vdots \\ a_i \\ \vdots \end{array} \right] &= a_0 g(x) + a_1 g(x) f(x) + a_2 g(x) f(x)^2 + \ldots \\ &= g(x) \left( a_0 + a_1 f(x) + a_2 f(x)^2 + \ldots \right) \\ &= g(x) A(f(x)) \end{split}$$ where $A(t) = a_0 + a_1 t + a_2 t^2 + \ldots$ is the formal power series of the sequence $(a_0, a_1, a_2, \ldots)$.

Observe that $ g(x) A(f(x))$ can be expanded as a formal power series $b_0 + b_1 x + b_2 x^2 + \ldots$ for some sequence $\{b_n\}_{n \in \mathbb{N}}$ after collecting coefficients for equal powers of $x$: applying $\mathcal{G}$ operator it is possibile to write $\mathcal{G}(\{b_n\}) = g(x) A(f(x))$. Since on the right side there is a product of two separable function, it does follow that the generic term of $\{b_n\}$ is a convolution by properties of $\mathcal{G}$, namely: $$ b_n = \sum_{i=0}^{n}{g_i r_{n-i}}$$ where coefficient $r_j$ depends on both finitely coefficients $a_0, \ldots, a_j$ both on infinitely coefficients $f_2,f_3,\ldots$

Product with a matrix

Let $M, N$ be two Riordan matrices such that $M = (g(x),f(x))$ and $N = (h(x),l(x))$. In order to study the product $M N$ consider the $i$-th column of matrix $N$, namely coefficients in the formal power series expansion of $h(x)l(x)^i$. By product by vector explanation above, coefficients of $i$-th column of $M N$ are denoted by series expansion of $g(x)h(f(x))l(f(x))^i$, hence repeating the same reasoning for all $i$, it is possible to write: $M N = (g(x)h(f(x)), l(f(x)))$ hence $M N$ is a Riordan matrix too.

The set of Riordan matrices with product operation is a group


In [37]:
def g(x): return 1
def f(x): return x

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


Out[37]:
\begin{equation} \left( 1, x \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 0 & 1 & & & & & & & & & \\ 0 & 0 & 1 & & & & & & & & \\ 0 & 0 & 0 & 1 & & & & & & & \\ 0 & 0 & 0 & 0 & 1 & & & & & & \\ 0 & 0 & 0 & 0 & 0 & 1 & & & & & \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & & & & \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & & & \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & & \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

Pascal triangle standard

In this section we'll built the standard Pascal triangle, developing the Riordan matrix $(g(x),f(x))$ that represent a matrix such that row $r$ contains coefficients of $(x + y)^r$, namely ${ {r} \choose {i} }$, for $i \in \{0,\ldots,r\}$.

Since the matrix $$M = \left({ {j} \choose {i} }\right)_{i,j \geq 0}$$ is well known, we proceed in two step in order to define functions $g(x)$ and $f(x)$, starting with the former one. Observe that $g(x)$ is the same as $C_0(x) = 1 + x + x^2 + x^3 + \ldots $, so it is a formal power series, where each coefficient equals 1, hence $g(x)$ is the generating function of the sequence $\{1_n\}_{n\in \mathbb{n}}$, which has a closed form: $$g(x) = \mathcal{G}\{1_n\} = \frac{1}{1-x}$$

Now set for $f(x)$. By definition of Riordan matrix, the expansion of $C_1(x) = g(x)f(x)$ as power series should collect coefficients from the second column, namely the natural numbers. Recall that the generating function of the sequence $\{n\}_{n\in \mathbb{N}}$ is: $$\mathcal{G} \{n\} = \mathcal{G}\{n1_n\} = x\frac{\partial \mathcal{G}\{1_n\}}{\partial x} = \frac{x}{(1-x)^2}$$

Hence the following equation yields $f(x)$: $$ \frac{1}{1-x}f(x) = \frac{x}{(1-x)^2}$$

The above reasoning is implemented with the following code:


In [2]:
def g(x): return 1/(1-x)
def f(x): return x/(1-x)

Latex(Riordan_matrix_latex_code(g, f, x, order=20))


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-5d52185184b5> in <module>()
      2 def f(x): return x/(1-x)
      3 
----> 4 Latex(Riordan_matrix_latex_code(g, f, x, order=20))

/home/mn/Developer/working-copies/uni/master-thesis/sympy/riordan-group.py in Riordan_matrix_latex_code(g, f, var, order)
     29     columns_as_power_series = (series(g(var) * f(var)**i,x=var,n=order) for i in range(order))
     30 
---> 31     coefficients_per_column = [col.as_coefficients_dict() for col in columns_as_power_series]
     32 
     33     matrix_rows = []

/home/mn/Developer/working-copies/uni/master-thesis/sympy/riordan-group.py in <listcomp>(.0)
     29     columns_as_power_series = (series(g(var) * f(var)**i,x=var,n=order) for i in range(order))
     30 
---> 31     coefficients_per_column = [col.as_coefficients_dict() for col in columns_as_power_series]
     32 
     33     matrix_rows = []

/home/mn/Developer/working-copies/uni/master-thesis/sympy/riordan-group.py in <genexpr>(.0)
     27                 + r'\end{array} \right]')
     28 
---> 29     columns_as_power_series = (series(g(var) * f(var)**i,x=var,n=order) for i in range(order))
     30 
     31     coefficients_per_column = [col.as_coefficients_dict() for col in columns_as_power_series]

/usr/local/lib/python3.4/site-packages/sympy/series/series.py in series(expr, x, x0, n, dir)
     10     """
     11     expr = sympify(expr)
---> 12     return expr.series(x, x0, n, dir)

/usr/local/lib/python3.4/site-packages/sympy/core/expr.py in series(self, x, x0, n, dir, logx)
   2433             # replace x with an x that has a positive assumption
   2434             xpos = C.Dummy('x', positive=True, finite=True)
-> 2435             rv = self.subs(x, xpos).series(xpos, x0, n, dir, logx=logx)
   2436             if n is None:
   2437                 return (s.subs(xpos, x) for s in rv)

/usr/local/lib/python3.4/site-packages/sympy/core/expr.py in series(self, x, x0, n, dir, logx)
   2440 
   2441         if n is not None:  # nseries handling
-> 2442             s1 = self._eval_nseries(x, n=n, logx=logx)
   2443             o = s1.getO() or S.Zero
   2444             if o:

/usr/local/lib/python3.4/site-packages/sympy/core/mul.py in _eval_nseries(self, x, n, logx)
   1444     def _eval_nseries(self, x, n, logx):
   1445         from sympy import powsimp
-> 1446         terms = [t.nseries(x, n=n, logx=logx) for t in self.args]
   1447         res = powsimp(self.func(*terms).expand(), combine='exp', deep=True)
   1448         if res.has(C.Order):

/usr/local/lib/python3.4/site-packages/sympy/core/mul.py in <listcomp>(.0)
   1444     def _eval_nseries(self, x, n, logx):
   1445         from sympy import powsimp
-> 1446         terms = [t.nseries(x, n=n, logx=logx) for t in self.args]
   1447         res = powsimp(self.func(*terms).expand(), combine='exp', deep=True)
   1448         if res.has(C.Order):

/usr/local/lib/python3.4/site-packages/sympy/core/expr.py in nseries(self, x, x0, n, dir, logx)
   2637             return self.series(x, x0, n, dir)
   2638         else:
-> 2639             return self._eval_nseries(x, n=n, logx=logx)
   2640 
   2641     def _eval_nseries(self, x, n, logx):

/usr/local/lib/python3.4/site-packages/sympy/core/power.py in _eval_nseries(self, x, n, logx)
   1149                     return self
   1150                 # now we have a type 1/f(x), that we know how to expand
-> 1151                 return (1/denominator)._eval_nseries(x, n=n, logx=logx)
   1152 
   1153         if e.has(Symbol):

/usr/local/lib/python3.4/site-packages/sympy/core/power.py in _eval_nseries(self, x, n, logx)
   1136                     terms.append(new_term)
   1137                 terms.append(O(x**n, x))
-> 1138                 return powsimp(Add(*terms), deep=True, combine='exp')
   1139             else:
   1140                 # negative powers are rewritten to the cases above, for

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/core/operations.py in __new__(cls, *args, **options)
     39             return args[0]
     40 
---> 41         c_part, nc_part, order_symbols = cls.flatten(args)
     42         is_commutative = not nc_part
     43         obj = cls._from_args(c_part + nc_part, is_commutative)

/usr/local/lib/python3.4/site-packages/sympy/core/add.py in flatten(cls, seq)
    241                 for o in order_factors:
    242                     # x + O(x) -> O(x)
--> 243                     if o.contains(t):
    244                         t = None
    245                         break

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/series/order.py in contains(self, expr)
    382             return r
    383         obj = self.func(expr, *self.args[1:])
--> 384         return self.contains(obj)
    385 
    386     def __contains__(self, other):

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/series/order.py in contains(self, expr)
    370             ratio = powsimp(ratio, deep=True, combine='exp')
    371             for s in common_symbols:
--> 372                 l = ratio.limit(s, point)
    373                 if not isinstance(l, C.Limit):
    374                     l = l != 0

/usr/local/lib/python3.4/site-packages/sympy/core/expr.py in limit(self, x, xlim, dir)
   2660         """
   2661         from sympy.series.limits import limit
-> 2662         return limit(self, x, xlim, dir)
   2663 
   2664     def compute_leading_term(self, x, logx=None):

/usr/local/lib/python3.4/site-packages/sympy/series/limits.py in limit(e, z, z0, dir)
     40     """
     41 
---> 42     return Limit(e, z, z0, dir).doit(deep=False)
     43 
     44 

/usr/local/lib/python3.4/site-packages/sympy/series/limits.py in doit(self, **hints)
    155 
    156         try:
--> 157             r = gruntz(e, z, z0, dir)
    158             if r is S.NaN:
    159                 raise PoleError()

/usr/local/lib/python3.4/site-packages/sympy/series/gruntz.py in gruntz(e, z, z0, dir)
    649         else:
    650             raise NotImplementedError("dir must be '+' or '-'")
--> 651         r = limitinf(e0, z)
    652 
    653     # This is a bit of a heuristic for nice results... we always rewrite

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/series/gruntz.py in limitinf(e, x)
    422         e = e.subs(x, p)
    423         x = p
--> 424     c0, e0 = mrv_leadterm(e, x)
    425     sig = sign(e0, x)
    426     if sig == 1:

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/series/gruntz.py in mrv_leadterm(e, x)
    505     f, logw = rewrite(exps, Omega, x, w)
    506     series = calculate_series(f, w, logx=logw)
--> 507     return series.leadterm(w)
    508 
    509 

/usr/local/lib/python3.4/site-packages/sympy/core/expr.py in leadterm(self, x)
   2747         l = self.as_leading_term(x)
   2748         d = C.Dummy('logx')
-> 2749         if l.has(C.log(x)):
   2750             l = l.subs(C.log(x), d)
   2751         c, e = l.as_coeff_exponent(x)

/usr/local/lib/python3.4/site-packages/sympy/core/cache.py in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/usr/local/lib/python3.4/functools.py in wrapper(*args, **kwds)
    450                         hits += 1
    451                         return result
--> 452                 result = user_function(*args, **kwds)
    453                 with lock:
    454                     if key in cache:

/usr/local/lib/python3.4/site-packages/sympy/core/function.py in __new__(cls, *args, **options)
    357 
    358         n = len(args)
--> 359         if n not in cls.nargs:
    360             # XXX: exception message must be in exactly this format to
    361             # make it work with NumPy's functions like vectorize(). See,

/usr/local/lib/python3.4/site-packages/sympy/core/function.py in nargs(self)
    166         # XXX it would be nice to handle this in __init__ but there are import
    167         # problems with trying to import FiniteSet there
--> 168         return FiniteSet(*self._nargs) if self._nargs else S.Naturals0
    169 
    170     def __repr__(cls):

/usr/local/lib/python3.4/site-packages/sympy/sets/sets.py in __new__(cls, *args, **kwargs)
   1589             args = list(map(sympify, args))
   1590 
-> 1591         args = list(ordered(frozenset(tuple(args)), Set._infimum_key))
   1592         obj = Basic.__new__(cls, *args)
   1593         obj._elements = frozenset(args)

/usr/local/lib/python3.4/site-packages/sympy/core/compatibility.py in ordered(seq, keys, default, warn)
    668                     raise ValueError(
    669                         'not enough keys to break ties: %s' % u)
--> 670         for v in d[k]:
    671             yield v
    672         d.pop(k)

/usr/local/lib/python3.4/site-packages/sympy/core/compatibility.py in ordered(seq, keys, default, warn)
    668                     raise ValueError(
    669                         'not enough keys to break ties: %s' % u)
--> 670         for v in d[k]:
    671             yield v
    672         d.pop(k)

/usr/local/lib/python3.4/site-packages/sympy/core/compatibility.py in ordered(seq, keys, default, warn)
    649         f = keys.pop(0)
    650         for a in seq:
--> 651             d[f(a)].append(a)
    652     else:
    653         if not default:

/usr/local/lib/python3.4/site-packages/sympy/core/compatibility.py in default_sort_key(item, order)
    501     from sympy.core.compatibility import iterable
    502 
--> 503     if isinstance(item, Basic):
    504         return item.sort_key(order=order)
    505 

KeyboardInterrupt: 

In [17]:
two_var_gen_fun = 1/(1-y*(1+x))
display(series(two_var_gen_fun,(1+x)))
display(series(two_var_gen_fun,y))
for k in range(5): display(series(y**k/(1-y)**(k+1),y,n=10))


$$1 + y \left(x + 1\right) + y^{2} \left(x + 1\right)^{2} + y^{3} \left(x + 1\right)^{3} + y^{4} \left(x + 1\right)^{4} + y^{5} \left(x + 1\right)^{5} + \mathcal{O}\left(\left(x + 1\right)^{6}; x\rightarrow-1\right)$$
$$1 + y \left(x + 1\right) + y^{2} \left(x^{2} + 2 x + 1\right) + y^{3} \left(x^{3} + 3 x^{2} + 3 x + 1\right) + y^{4} \left(x^{4} + 4 x^{3} + 6 x^{2} + 4 x + 1\right) + y^{5} \left(x^{5} + 5 x^{4} + 10 x^{3} + 10 x^{2} + 5 x + 1\right) + \mathcal{O}\left(y^{6}\right)$$
$$1 + y + y^{2} + y^{3} + y^{4} + y^{5} + y^{6} + y^{7} + y^{8} + y^{9} + \mathcal{O}\left(y^{10}\right)$$
$$y + 2 y^{2} + 3 y^{3} + 4 y^{4} + 5 y^{5} + 6 y^{6} + 7 y^{7} + 8 y^{8} + 9 y^{9} + \mathcal{O}\left(y^{10}\right)$$
$$y^{2} + 3 y^{3} + 6 y^{4} + 10 y^{5} + 15 y^{6} + 21 y^{7} + 28 y^{8} + 36 y^{9} + \mathcal{O}\left(y^{10}\right)$$
$$y^{3} + 4 y^{4} + 10 y^{5} + 20 y^{6} + 35 y^{7} + 56 y^{8} + 84 y^{9} + \mathcal{O}\left(y^{10}\right)$$
$$y^{4} + 5 y^{5} + 15 y^{6} + 35 y^{7} + 70 y^{8} + 126 y^{9} + \mathcal{O}\left(y^{10}\right)$$

Pascal triangle enhanced

In this section we approach a variant of the above triangle, starting to work with a matrix $M = (b_{nj})_{n,j \geq 0}$ where coefficients aren't explicitly defined but obey to the recurrence: $$ b_{n+1,j} = b_{n, j-1} + b_{n, j+1}$$

where $j > 0$. Assume the relation holds for all $n \in \mathbb{N}$ so it is possible to apply the Identity principle: $$ \begin{split} \mathcal{G}\{b_{n+1,j}\} &= \mathcal{G}\{b_{n, j-1} + b_{n, j+1}\} \\ \mathcal{G}\{b_{n+1,j}\} &= \mathcal{G}\{b_{n, j-1}\} + \mathcal{G}\{b_{n, j+1}\} \quad \text{ by linearity of } \mathcal{G} \\ \frac{\mathcal{G}\{b_{n,j}\}-b_{0j}}{x} &= \mathcal{G}\{b_{n, j-1}\} + \mathcal{G}\{b_{n, j+1}\} \quad \text{ by forward translation of } \mathcal{G} \\ C_j(x) &= xC_{j-1}(x) + xC_{j+1}(x) \quad \forall j > 0: b_{0j} = 0 \end{split}$$

Another way to prove the same result, is to observe that $b_{n+1,j}$ is a convolution of the two terms $b_{n,j-1}$ and $b_{n,j+1}$, hence there must exists two functions, say $h_j(x) = h_{0j} + h_{1j} x + h_{2j} x^2 + \ldots$, where coefficient $h_{i,j}= b_{i,j-1} + b_{i,j+1}$ and $l(x) = l_0 + l_1 x + l_2 x^2 + \ldots$, such that: $$\mathcal{G}\left\lbrace\sum_{k=0}^{n+1}{h_{k,j} l_{n+1-k}}\right\rbrace = h_j(x)l(x)$$

Choose $l(x) = x$ because the entire sum should reduce to $b_{n,j-1} + b_{n,j+1}$ which equals $h_{nj}$, hence: $$\begin{split} \mathcal{G}\left\lbrace\sum_{k=0}^{n+1}{h_{k,j} l_{n+1-k}}\right\rbrace &= \mathcal{G}\left\lbrace{h_{n,j} l_{1}}\right\rbrace \\ &=\mathcal{G}\left\lbrace{b_{n,j-1} + b_{n,j+1}}\right\rbrace \\ &=\mathcal{G}\left\lbrace{b_{n,j-1}}\right\rbrace + \mathcal{G}\left\lbrace{b_{n,j+1}}\right\rbrace \\ &= C_{j-1}(x) + C_{j+1}(x)\end{split}$$

It follows that $h_j(x) = C_{j-1}(x) + C_{j+1}(x)$ as obtained in the former derivation.


In [30]:
def g(x): return 1/sqrt(1 -4*x**2)
def f(x): return (1-sqrt(1 -4*x**2))/(2*x)

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


Out[30]:
\begin{equation} \left( \frac{1}{\sqrt{- 4 x^{2} + 1}}, \frac{1}{2 x} \left(- \sqrt{- 4 x^{2} + 1} + 1\right) \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 0 & 1 & & & & & & & & & \\ 2 & 0 & 1 & & & & & & & & \\ 0 & 3 & 0 & 1 & & & & & & & \\ 6 & 0 & 4 & 0 & 1 & & & & & & \\ 0 & 10 & 0 & 5 & 0 & 1 & & & & & \\ 20 & 0 & 15 & 0 & 6 & 0 & 1 & & & & \\ 0 & 35 & 0 & 21 & 0 & 7 & 0 & 1 & & & \\ 70 & 0 & 56 & 0 & 28 & 0 & 8 & 0 & 1 & & \\ 0 & 126 & 0 & 84 & 0 & 36 & 0 & 9 & 0 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [32]:
series(f(x),x,n=20)


Out[32]:
$$x + x^{3} + 2 x^{5} + 5 x^{7} + 14 x^{9} + 42 x^{11} + 132 x^{13} + 429 x^{15} + 1430 x^{17} + 4862 x^{19} + \mathcal{O}\left(x^{20}\right)$$

In [12]:
def g(x): return (1-x**2)/(x**2+1)
def f(x): return x/(1+x**2)

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


Out[12]:
\begin{equation} \left( \frac{- x^{2} + 1}{x^{2} + 1}, \frac{x}{x^{2} + 1} \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 0 & 1 & & & & & & & & & \\ -2 & 0 & 1 & & & & & & & & \\ 0 & -3 & 0 & 1 & & & & & & & \\ 2 & 0 & -4 & 0 & 1 & & & & & & \\ 0 & 5 & 0 & -5 & 0 & 1 & & & & & \\ -2 & 0 & 9 & 0 & -6 & 0 & 1 & & & & \\ 0 & -7 & 0 & 14 & 0 & -7 & 0 & 1 & & & \\ 2 & 0 & -16 & 0 & 20 & 0 & -8 & 0 & 1 & & \\ 0 & 9 & 0 & -30 & 0 & 27 & 0 & -9 & 0 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [14]:
series(f(x),x,n=20)


Out[14]:
$$x - x^{3} + x^{5} - x^{7} + x^{9} - x^{11} + x^{13} - x^{15} + x^{17} - x^{19} + \mathcal{O}\left(x^{20}\right)$$

In [4]:
def g(x): return 1/sqrt(1-2*x-3*x**2)
def f(x): return (1-x-sqrt(1-2*x-3*x**2))/(2*x)

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


Out[4]:
\begin{equation} \left( \frac{1}{\sqrt{- \left(x + 1\right) \left(3 x - 1\right)}}, - \frac{1}{2 x} \left(x + \sqrt{- 3 x^{2} - 2 x + 1} - 1\right) \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 1 & 1 & & & & & & & & & \\ 3 & 2 & 1 & & & & & & & & \\ 7 & 6 & 3 & 1 & & & & & & & \\ 19 & 16 & 10 & 4 & 1 & & & & & & \\ 51 & 45 & 30 & 15 & 5 & 1 & & & & & \\ 141 & 126 & 90 & 50 & 21 & 6 & 1 & & & & \\ 393 & 357 & 266 & 161 & 77 & 28 & 7 & 1 & & & \\ 1107 & 1016 & 784 & 504 & 266 & 112 & 36 & 8 & 1 & & \\ 3139 & 2907 & 2304 & 1554 & 882 & 414 & 156 & 45 & 9 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [7]:
series(f(x),x,n=10)
display(series((3+2*x+x**2)/(1-x), n=10))


$$3 + 5 x + 6 x^{2} + 6 x^{3} + 6 x^{4} + 6 x^{5} + 6 x^{6} + 6 x^{7} + 6 x^{8} + 6 x^{9} + \mathcal{O}\left(x^{10}\right)$$

In [12]:
def g(x): return Integer(1)
def f(x): return x/(1-x)

for n in range(1,6):
    display(series(f(x)**n, n=10))

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


$$x + x^{2} + x^{3} + x^{4} + x^{5} + x^{6} + x^{7} + x^{8} + x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{2} + 2 x^{3} + 3 x^{4} + 4 x^{5} + 5 x^{6} + 6 x^{7} + 7 x^{8} + 8 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{3} + 3 x^{4} + 6 x^{5} + 10 x^{6} + 15 x^{7} + 21 x^{8} + 28 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{4} + 4 x^{5} + 10 x^{6} + 20 x^{7} + 35 x^{8} + 56 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{5} + 5 x^{6} + 15 x^{7} + 35 x^{8} + 70 x^{9} + \mathcal{O}\left(x^{10}\right)$$
Out[12]:
\begin{equation} \left( 1, - \frac{x}{x - 1} \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 0 & 1 & & & & & & & & & \\ 0 & 1 & 1 & & & & & & & & \\ 0 & 1 & 2 & 1 & & & & & & & \\ 0 & 1 & 3 & 3 & 1 & & & & & & \\ 0 & 1 & 4 & 6 & 4 & 1 & & & & & \\ 0 & 1 & 5 & 10 & 10 & 5 & 1 & & & & \\ 0 & 1 & 6 & 15 & 20 & 15 & 6 & 1 & & & \\ 0 & 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 & & \\ 0 & 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [7]:
def d(t): return (1-t)/(1-2*t)
def h(t): return (1+t)/((1-t)*t)

Latex(Riordan_matrix_latex_code(d, h, t, order=10))


Out[7]:
\begin{equation} \left( \frac{t - 1}{2 t - 1}, - \frac{t + 1}{t \left(t - 1\right)} \right) = \left[ \begin{array}{ccccccccccc}1 & 3 & 14 & 72 & 384 & 2088 & 11492 & 63780 & 356144 & 1998000 & \\ 1 & 6 & 32 & 172 & 936 & 5144 & 28484 & 158652 & 887792 & 4986736 & \\ 2 & 12 & 68 & 380 & 2120 & 11848 & 66388 & 372996 & 2100944 & 11860880 & \\ 4 & 24 & 140 & 804 & 4584 & 26056 & 147956 & 840156 & 4773200 & 27138640 & \\ 8 & 48 & 284 & 1660 & 9624 & 55512 & 319204 & 1832100 & 10504560 & 60197360 & \\ 16 & 96 & 572 & 3380 & 19832 & 115736 & 672740 & 3899260 & 22554160 & 130268080 & \\ 32 & 192 & 1148 & 6828 & 40392 & 237800 & 1394420 & 8150340 & 47516560 & 276462032 & \\ 64 & 384 & 2300 & 13732 & 81672 & 483880 & 2856660 & 16812060 & 98677392 & 577867408 & \\ 128 & 768 & 4604 & 27548 & 164408 & 978360 & 5805060 & 34348772 & 202727984 & 1193793584 & \\ 256 & 1536 & 9212 & 55188 & 330072 & 1970040 & 11731652 & 69701820 & 413198192 & 2444317680 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [3]:
def curious(m): return ((1 + x)**m)*x**(m+1)/(1 -x -x**2)**(m+1)
[display(series(curious(m),n=10)) for m in range(5)]; None


$$x + x^{2} + 2 x^{3} + 3 x^{4} + 5 x^{5} + 8 x^{6} + 13 x^{7} + 21 x^{8} + 34 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{2} + 3 x^{3} + 7 x^{4} + 15 x^{5} + 30 x^{6} + 58 x^{7} + 109 x^{8} + 201 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{3} + 5 x^{4} + 16 x^{5} + 43 x^{6} + 104 x^{7} + 235 x^{8} + 506 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{4} + 7 x^{5} + 29 x^{6} + 95 x^{7} + 271 x^{8} + 705 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$x^{5} + 9 x^{6} + 46 x^{7} + 179 x^{8} + 591 x^{9} + \mathcal{O}\left(x^{10}\right)$$

In [6]:
def g(x): return Integer(1)
def f(x): return x*(1+x)

Latex(Riordan_matrix_latex_code(g, f, x, order=10))


Out[6]:
\begin{equation} \left( 1, x \left(x + 1\right) \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 0 & 1 & & & & & & & & & \\ 0 & 1 & 1 & & & & & & & & \\ 0 & 0 & 2 & 1 & & & & & & & \\ 0 & 0 & 1 & 3 & 1 & & & & & & \\ 0 & 0 & 0 & 3 & 4 & 1 & & & & & \\ 0 & 0 & 0 & 1 & 6 & 5 & 1 & & & & \\ 0 & 0 & 0 & 0 & 4 & 10 & 6 & 1 & & & \\ 0 & 0 & 0 & 0 & 1 & 10 & 15 & 7 & 1 & & \\ 0 & 0 & 0 & 0 & 0 & 5 & 20 & 21 & 8 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

Identities and inverse relations


In [20]:
s = series((1-x)**(2*n),x,n=10).subs(n,4)
s, s.coeff(x**5)-s.coeff(x**4)


Out[20]:
$$\left ( 1 - 8 x + 28 x^{2} - 56 x^{3} + 70 x^{4} - 56 x^{5} + 28 x^{6} - 8 x^{7} + x^{8} + \mathcal{O}\left(x^{10}\right), \quad -126\right )$$

In [21]:
series((1+x)**5,x,n=10)


Out[21]:
$$x^{5} + 5 x^{4} + 10 x^{3} + 10 x^{2} + 5 x + 1$$

In [28]:
list(map(display, (series((1/sqrt(1+2*x-3*x**2))*(1+x)**(n-1) *(1+x),x,n=10) for n in range(5))))
print("\n")
list(map(display, (series((1/sqrt(1+2*x-3*x**2))*(1+x)**(n-1),x,n=10) for n in range(5))))
None


$$1 - x + 3 x^{2} - 7 x^{3} + 19 x^{4} - 51 x^{5} + 141 x^{6} - 393 x^{7} + 1107 x^{8} - 3139 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + 2 x^{2} - 4 x^{3} + 12 x^{4} - 32 x^{5} + 90 x^{6} - 252 x^{7} + 714 x^{8} - 2032 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + x + 2 x^{2} - 2 x^{3} + 8 x^{4} - 20 x^{5} + 58 x^{6} - 162 x^{7} + 462 x^{8} - 1318 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + 2 x + 3 x^{2} + 6 x^{4} - 12 x^{5} + 38 x^{6} - 104 x^{7} + 300 x^{8} - 856 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + 3 x + 5 x^{2} + 3 x^{3} + 6 x^{4} - 6 x^{5} + 26 x^{6} - 66 x^{7} + 196 x^{8} - 556 x^{9} + \mathcal{O}\left(x^{10}\right)$$

$$1 - 2 x + 5 x^{2} - 12 x^{3} + 31 x^{4} - 82 x^{5} + 223 x^{6} - 616 x^{7} + 1723 x^{8} - 4862 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 - x + 3 x^{2} - 7 x^{3} + 19 x^{4} - 51 x^{5} + 141 x^{6} - 393 x^{7} + 1107 x^{8} - 3139 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + 2 x^{2} - 4 x^{3} + 12 x^{4} - 32 x^{5} + 90 x^{6} - 252 x^{7} + 714 x^{8} - 2032 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + x + 2 x^{2} - 2 x^{3} + 8 x^{4} - 20 x^{5} + 58 x^{6} - 162 x^{7} + 462 x^{8} - 1318 x^{9} + \mathcal{O}\left(x^{10}\right)$$
$$1 + 2 x + 3 x^{2} + 6 x^{4} - 12 x^{5} + 38 x^{6} - 104 x^{7} + 300 x^{8} - 856 x^{9} + \mathcal{O}\left(x^{10}\right)$$

$A$ and $Z$ sequences for characterizing Riordan arrays

Fibonacci triangle


In [21]:
def d(x): return 1/(1-x-x**2)
def h(x): return (1-sqrt(1-4*x))/2

Latex(Riordan_matrix_latex_code(d, h, t, order=10))


Out[21]:
\begin{equation} \left( - \frac{1}{t^{2} + t - 1}, - \frac{1}{2} \left(\sqrt{- 4 t + 1} - 1\right) \right) = \left[ \begin{array}{ccccccccccc}1 & & & & & & & & & & \\ 1 & 1 & & & & & & & & & \\ 2 & 2 & 1 & & & & & & & & \\ 3 & 5 & 3 & 1 & & & & & & & \\ 5 & 12 & 9 & 4 & 1 & & & & & & \\ 8 & 31 & 26 & 14 & 5 & 1 & & & & & \\ 13 & 85 & 77 & 46 & 20 & 6 & 1 & & & & \\ 21 & 248 & 235 & 150 & 73 & 27 & 7 & 1 & & & \\ 34 & 762 & 741 & 493 & 258 & 108 & 35 & 8 & 1 & & \\ 55 & 2440 & 2406 & 1644 & 903 & 410 & 152 & 44 & 9 & 1 & \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots\end{array} \right] \end{equation}

In [19]:
Eq(h(t).factor(), series(h(t),n=10))


Out[19]:
$$- \frac{1}{2} \left(\sqrt{- 4 t + 1} - 1\right) = t + t^{2} + 2 t^{3} + 5 t^{4} + 14 t^{5} + 42 t^{6} + 132 t^{7} + 429 t^{8} + 1430 t^{9} + \mathcal{O}\left(t^{10}\right)$$

In [33]:
one_less_two_powers = x/((1-x)*(1-2*x))
taken_apart = one_less_two_powers.apart()

display(taken_apart)
display(series(1/(1-2*x)))
display(series(1/(x-1)))

series(one_less_two_powers, n=10)


$$- \frac{1}{2 x - 1} + \frac{1}{x - 1}$$
$$1 + 2 x + 4 x^{2} + 8 x^{3} + 16 x^{4} + 32 x^{5} + \mathcal{O}\left(x^{6}\right)$$
$$-1 - x - x^{2} - x^{3} - x^{4} - x^{5} + \mathcal{O}\left(x^{6}\right)$$
Out[33]:
$$x + 3 x^{2} + 7 x^{3} + 15 x^{4} + 31 x^{5} + 63 x^{6} + 127 x^{7} + 255 x^{8} + 511 x^{9} + \mathcal{O}\left(x^{10}\right)$$

In [85]:
def autocorrelation_polynomial(x=x,y=y): return (1 + x**2 * y**2 + x**3 * y**2)
def avoiding_pattern_expr(x=x,y=y): return autocorrelation_polynomial(x,y) / ((1-x-y)*autocorrelation_polynomial(x,y) + x**4 * y**2)

display(avoiding_pattern_expr())
display(avoiding_pattern_expr(x,t/x))

for_thm = avoiding_pattern_expr(x,t)
for_thm.series(x,n=2).coeff(x).series()


$$\frac{x^{3} y^{2} + x^{2} y^{2} + 1}{x^{4} y^{2} + \left(- x - y + 1\right) \left(x^{3} y^{2} + x^{2} y^{2} + 1\right)}$$
$$\frac{t^{2} x + t^{2} + 1}{t^{2} x^{2} + \left(- \frac{t}{x} - x + 1\right) \left(t^{2} x + t^{2} + 1\right)}$$
Out[85]:
$$1 + 2 t + 3 t^{2} + 4 t^{3} + 5 t^{4} + 6 t^{5} + \mathcal{O}\left(t^{6}\right)$$

In [72]:
# getting the series over *x* means asking for *rows*'s generating functions
x_series = series(avoiding_pattern_expr(), x,n=10)

# get generating function of row 4th, expand it 'column-wise' (over *y*) in order to build row 4th as desired
avoiding_pattern_expr(), x_series.coeff(x**4).series(y,n=10)


Out[72]:
$$\left ( \frac{1}{x^{2} y - x - y + 1}, \quad 1 + 2 y + 4 y^{2} + 8 y^{3} + 16 y^{4} + 31 y^{5} + 57 y^{6} + 99 y^{7} + 163 y^{8} + 256 y^{9} + \mathcal{O}\left(y^{10}\right)\right )$$

In [91]:
series(1/(1-t),t,n=10)


Out[91]:
$$1 + t + t^{2} + t^{3} + t^{4} + t^{5} + t^{6} + t^{7} + t^{8} + t^{9} + \mathcal{O}\left(t^{10}\right)$$

In [69]:
# pattern p: 011
def autocorrelation_polynomial(x=x,y=y): return 1
def avoiding_pattern_expr(x=x,y=y): return autocorrelation_polynomial(x,y) / ((1-x-y)*autocorrelation_polynomial(x,y) + x**2 * y**1)

display(avoiding_pattern_expr())
display(avoiding_pattern_expr(x,t/x))

for_thm = avoiding_pattern_expr(x,t/x)
for_thm.series(x,n=2),for_thm.series(t,n=2)


$$\frac{1}{x^{2} y - x - y + 1}$$
$$\frac{1}{t x - \frac{t}{x} - x + 1}$$
Out[69]:
$$\left ( - \frac{x}{t} + \mathcal{O}\left(x^{2}\right), \quad \frac{1}{- x + 1} + t \left(- \frac{x}{\left(- x + 1\right)^{2}} + \frac{1}{\left(- x + 1\right) \left(- x^{2} + x\right)}\right) + \mathcal{O}\left(t^{2}\right)\right )$$

In [11]:
def R(n,k): return k/(2*(k-n-1))
[display(series(R(n,k),x=n,n=10)) for k in range(10)]
[display(series(R(n,k),x=k,n=10)) for n in range(10)]

display(R(n, k))


$$0$$
$$- \frac{1}{2 n}$$
$$1 + n + n^{2} + n^{3} + n^{4} + n^{5} + n^{6} + n^{7} + n^{8} + n^{9} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{3}{4} + \frac{3 n}{8} + \frac{3 n^{2}}{16} + \frac{3 n^{3}}{32} + \frac{3 n^{4}}{64} + \frac{3 n^{5}}{128} + \frac{3 n^{6}}{256} + \frac{3 n^{7}}{512} + \frac{3 n^{8}}{1024} + \frac{3 n^{9}}{2048} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{2}{3} + \frac{2 n}{9} + \frac{2 n^{2}}{27} + \frac{2 n^{3}}{81} + \frac{2 n^{4}}{243} + \frac{2 n^{5}}{729} + \frac{2 n^{6}}{2187} + \frac{2 n^{7}}{6561} + \frac{2 n^{8}}{19683} + \frac{2 n^{9}}{59049} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{5}{8} + \frac{5 n}{32} + \frac{5 n^{2}}{128} + \frac{5 n^{3}}{512} + \frac{5 n^{4}}{2048} + \frac{5 n^{5}}{8192} + \frac{5 n^{6}}{32768} + \frac{5 n^{7}}{131072} + \frac{5 n^{8}}{524288} + \frac{5 n^{9}}{2097152} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{3}{5} + \frac{3 n}{25} + \frac{3 n^{2}}{125} + \frac{3 n^{3}}{625} + \frac{3 n^{4}}{3125} + \frac{3 n^{5}}{15625} + \frac{3 n^{6}}{78125} + \frac{3 n^{7}}{390625} + \frac{3 n^{8}}{1953125} + \frac{3 n^{9}}{9765625} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{7}{12} + \frac{7 n}{72} + \frac{7 n^{2}}{432} + \frac{7 n^{3}}{2592} + \frac{7 n^{4}}{15552} + \frac{7 n^{5}}{93312} + \frac{7 n^{6}}{559872} + \frac{7 n^{7}}{3359232} + \frac{7 n^{8}}{20155392} + \frac{7 n^{9}}{120932352} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{4}{7} + \frac{4 n}{49} + \frac{4 n^{2}}{343} + \frac{4 n^{3}}{2401} + \frac{4 n^{4}}{16807} + \frac{4 n^{5}}{117649} + \frac{4 n^{6}}{823543} + \frac{4 n^{7}}{5764801} + \frac{4 n^{8}}{40353607} + \frac{4 n^{9}}{282475249} + \mathcal{O}\left(n^{10}\right)$$
$$\frac{9}{16} + \frac{9 n}{128} + \frac{9 n^{2}}{1024} + \frac{9 n^{3}}{8192} + \frac{9 n^{4}}{65536} + \frac{9 n^{5}}{524288} + \frac{9 n^{6}}{4194304} + \frac{9 n^{7}}{33554432} + \frac{9 n^{8}}{268435456} + \frac{9 n^{9}}{2147483648} + \mathcal{O}\left(n^{10}\right)$$
$$- \frac{k}{2} - \frac{k^{2}}{2} - \frac{k^{3}}{2} - \frac{k^{4}}{2} - \frac{k^{5}}{2} - \frac{k^{6}}{2} - \frac{k^{7}}{2} - \frac{k^{8}}{2} - \frac{k^{9}}{2} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{4} - \frac{k^{2}}{8} - \frac{k^{3}}{16} - \frac{k^{4}}{32} - \frac{k^{5}}{64} - \frac{k^{6}}{128} - \frac{k^{7}}{256} - \frac{k^{8}}{512} - \frac{k^{9}}{1024} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{6} - \frac{k^{2}}{18} - \frac{k^{3}}{54} - \frac{k^{4}}{162} - \frac{k^{5}}{486} - \frac{k^{6}}{1458} - \frac{k^{7}}{4374} - \frac{k^{8}}{13122} - \frac{k^{9}}{39366} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{8} - \frac{k^{2}}{32} - \frac{k^{3}}{128} - \frac{k^{4}}{512} - \frac{k^{5}}{2048} - \frac{k^{6}}{8192} - \frac{k^{7}}{32768} - \frac{k^{8}}{131072} - \frac{k^{9}}{524288} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{10} - \frac{k^{2}}{50} - \frac{k^{3}}{250} - \frac{k^{4}}{1250} - \frac{k^{5}}{6250} - \frac{k^{6}}{31250} - \frac{k^{7}}{156250} - \frac{k^{8}}{781250} - \frac{k^{9}}{3906250} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{12} - \frac{k^{2}}{72} - \frac{k^{3}}{432} - \frac{k^{4}}{2592} - \frac{k^{5}}{15552} - \frac{k^{6}}{93312} - \frac{k^{7}}{559872} - \frac{k^{8}}{3359232} - \frac{k^{9}}{20155392} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{14} - \frac{k^{2}}{98} - \frac{k^{3}}{686} - \frac{k^{4}}{4802} - \frac{k^{5}}{33614} - \frac{k^{6}}{235298} - \frac{k^{7}}{1647086} - \frac{k^{8}}{11529602} - \frac{k^{9}}{80707214} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{16} - \frac{k^{2}}{128} - \frac{k^{3}}{1024} - \frac{k^{4}}{8192} - \frac{k^{5}}{65536} - \frac{k^{6}}{524288} - \frac{k^{7}}{4194304} - \frac{k^{8}}{33554432} - \frac{k^{9}}{268435456} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{18} - \frac{k^{2}}{162} - \frac{k^{3}}{1458} - \frac{k^{4}}{13122} - \frac{k^{5}}{118098} - \frac{k^{6}}{1062882} - \frac{k^{7}}{9565938} - \frac{k^{8}}{86093442} - \frac{k^{9}}{774840978} + \mathcal{O}\left(k^{10}\right)$$
$$- \frac{k}{20} - \frac{k^{2}}{200} - \frac{k^{3}}{2000} - \frac{k^{4}}{20000} - \frac{k^{5}}{200000} - \frac{k^{6}}{2000000} - \frac{k^{7}}{20000000} - \frac{k^{8}}{200000000} - \frac{k^{9}}{2000000000} + \mathcal{O}\left(k^{10}\right)$$
$$\frac{k}{2 k - 2 n - 2}$$

In [12]:
def R(n,k): return (k-1)/n
[display(series(R(n,k),x=n,n=10)) for k in range(10)]
[display(series(R(n,k),x=k,n=10)) for n in range(10)]

display(R(n, k))


$$- \frac{1}{n}$$
$$0$$
$$\frac{1}{n}$$
$$\frac{2}{n}$$
$$\frac{3}{n}$$
$$\frac{4}{n}$$
$$\frac{5}{n}$$
$$\frac{6}{n}$$
$$\frac{7}{n}$$
$$\frac{8}{n}$$
$$\mathrm{NaN}$$
$$k - 1$$
$$\frac{k}{2} - \frac{1}{2}$$
$$\frac{k}{3} - \frac{1}{3}$$
$$\frac{k}{4} - \frac{1}{4}$$
$$\frac{k}{5} - \frac{1}{5}$$
$$\frac{k}{6} - \frac{1}{6}$$
$$\frac{k}{7} - \frac{1}{7}$$
$$\frac{k}{8} - \frac{1}{8}$$
$$\frac{k}{9} - \frac{1}{9}$$
$$\frac{1}{n} \left(k - 1\right)$$

In [26]:
def f_1(n): return factorial(3*n+1)*factorial(2*n-5)*factorial(n+2)**2
simplify(Sum(f_1(n-k)/f_1(n), (k,0,3)).doit())


Out[26]:
$$\frac{1259712 n^{21} - 32122656 n^{20} + 337497840 n^{19} - 1801755576 n^{18} + 4336342776 n^{17} + 2570279040 n^{16} - 43035418368 n^{15} + 91393795584 n^{14} + 11567820816 n^{13} - 336081971988 n^{12} + 441211799952 n^{11} + 127611418068 n^{10} - 724739702184 n^{9} + 417817026612 n^{8} + 257433353964 n^{7} - 333322752150 n^{6} + 62126544750 n^{5} + 31820652174 n^{4} - 9239452410 n^{3} + 25382700 n^{2} + 1}{216 n^{3} \left(n - 5\right) \left(n - 4\right) \left(n - 3\right) \left(n - 2\right) \left(n - 1\right) \left(n + 1\right)^{2} \left(n + 2\right)^{2} \left(2 n - 9\right) \left(2 n - 7\right) \left(2 n - 5\right) \left(3 n - 7\right) \left(3 n - 5\right) \left(3 n - 4\right) \left(3 n - 2\right) \left(3 n - 1\right) \left(3 n + 1\right)}$$

Printing and displaying stuff

In this foot section we save some display tricks in order to support the implementation of a function that builds Riordan coefficient matrix:


In [4]:
from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')


Out[4]:
$$F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx$$

In [52]:
from IPython.display import Latex
Latex(r"""\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0 
\end{eqnarray}""")
Latex(r"""\[ 4 \]""")


Out[52]:
\[ 4 \]

In [6]:
from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))


$$F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx$$